
package com.unbank.wsdl;

/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.xml.namespace.QName;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

import com.unbank.utl.ConnectionFactory;

import net.sf.json.JSONObject;

/**
 * This class was generated by Apache CXF 2.1.3
 * Mon Aug 11 14:15:52 GMT+08:00 2014
 * Generated source version: 2.1.3
 * 
 */

public final class Autoclassinterface_AutoclassinterfaceImplPort_Client {

    private static final QName SERVICE_NAME = new QName("http://cxfinterface.unbank.com/", "AutoclassinterfaceImplService");

    private Autoclassinterface_AutoclassinterfaceImplPort_Client() {
    }

    public static void main(String args[]) throws Exception {
        
//        FileInputStream f = new FileInputStream("d:\\fenlei.txt"); 
//		BufferedReader dr=new BufferedReader(new InputStreamReader(f));
//		String line =  dr.readLine();
//		StringBuffer sb=new StringBuffer();
//		while(line!= null){ 
//			sb.append(line);   
//			line = dr.readLine();
//		} 
//		f.close();
//		dr.close();
		
		long start=System.currentTimeMillis();
		ResultSet rs = null;
		PreparedStatement ps = null;
		Connection con=null;
		try{
			
			con = ConnectionFactory.getConnection("form2");
			con.setAutoCommit(true);
			if (con.isClosed()) {
				throw new IllegalStateException("connection is close");
			}
//			ps = con.prepareStatement("select * from (select c.score,p2.*,p1.crawl_title from ptf_crawl p1 left join ptf_crawl_text p2 on p1.crawl_id=p2.crawl_id left join (select crawl_id,max(score) score from contrastrecord group by crawl_id) c on p1.crawl_id=c.crawl_id where p1.crawl_time<'2014-08-10' and p1.crawl_time>='2014-08-9'  order by p1.crawl_id desc ) d order by score desc");
			ps = con.prepareStatement("select p1.* from ptf_crawl p1 left join ptf_crawl_text p2 on p1.crawl_id=p2.crawl_id where p1.crawl_time<'2014-08-08' and p1.crawl_time>='2014-08-07'  order by p1.crawl_id desc ");
			rs = ps.executeQuery();
			BufferedWriter bw = new BufferedWriter(new FileWriter("d:\\keyword.html", true));
			bw.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
			bw.write("<html>");
			bw.write("<head>");
			bw.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
			bw.write("<title>测试</title>");
			bw.write("</head>");
			bw.write("<body><table><tr><th>编号</th><th>新闻编号</th><th>新闻名称</th><th>分类</th><th>关键词</th></tr>");
			int i=1;
			while (rs.next()){
				
				String crawl_id=rs.getString("crawl_id");
				String crawl_title=rs.getString("crawl_title");
				
				
				URL wsdlURL = AutoclassinterfaceImplService.WSDL_LOCATION;
				AutoclassinterfaceImplService ss = new AutoclassinterfaceImplService(wsdlURL, SERVICE_NAME);
		        Autoclassinterface port = ss.getAutoclassinterfaceImplPort(); 
		        JSONObject jsonObj = new JSONObject();
				jsonObj.put("content", "");
				jsonObj.put("id", crawl_id);
				jsonObj.put("title", "");
				
		        java.lang.String _comparesimilarity_arg0 = jsonObj.toString();
		        java.lang.String _comparesimilarity__return = port.comparesimilarity(_comparesimilarity_arg0);
		        
		        JSONObject demoJson = new JSONObject(_comparesimilarity__return);
				
				String classvalue=demoJson.getString("class");
				if(!classvalue.equals("-1")){
					String type="";
					if(classvalue.equals("1"))type="宏观";
					else if(classvalue.equals("2"))type="银行";
					else if(classvalue.equals("3"))type="互联网";
					else if(classvalue.equals("4"))type="监管";
					String keyword=demoJson.getString("keyword");
					bw.write("<tr><td>"+i+"</td><td><a href='http://10.0.0.51:8088/crawler/item.htm?id="+crawl_id+"' target='_blank'>"+crawl_id+"</a></td><td>"+crawl_title+"</td><td>"+type+"</td><td>"+keyword+"</td></tr>");
			        i++;
				}
			}
			bw.write("</table></body>");
			bw.flush();
	        bw.close();
		}catch(Exception e){
			e.printStackTrace();
		}
			
		
		long end=System.currentTimeMillis();
		System.out.println("耗时----------------"+(end-start));

    }

}
